<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            width: 100%;
            background: url(./img/bg.jpeg) repeat-x;
        }
        main{
            margin: 100px auto;
            width: 400px;
            height: 600px;
            background-color: rgb(239, 239, 239);
            border-radius: 15px;
        }
        main header{
            height:80px;
            width: 100%;
            background-color: rgb(86, 192, 234);
            border-radius: 10px 10px 0 0;
            color: white;
            font-size: 25px;
            text-align: center;
            line-height: 80px;
        }
        main .center{
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: left;
        }
        main  .center input{
            margin-top: 30px;
            width:80%;
            height: 40px ;
            border-radius: 5px;
            padding-left: 20px;
            border: 1px solid gray;
            background-color: transparent;
            outline: none;
        }
        main .center .lianjie{
            width:80%;
            height: 40px ;
            margin-top: 20px;
            text-align: left;
        }
        main .center .lianjie a{
            text-decoration: none;
        }
        main .center button{
            width: 90px ;
            height: 40px;
            color: white;
            background-color: rgb(106, 218, 112);
            border-radius: 10px;
            border:1px solid rgb(218, 218, 218);
            
        }
    </style>
</head>
<body>
    <main>
        <header>注册</header>
        <div class="center">
            <input type="text" placeholder="输入手机号">
            <input type="text" placeholder="输入用户名">
            <input type="password" placeholder="输入密码">
            <input type="password" placeholder="确认密码">
            <input type="text" placeholder="输入邮箱">
            <div class="lianjie"><a href="./main.html">已有账号，去登录</a></div>
            <button>注册</button>
        </div>
    </main>
</body>
</html>
<script src="./axios.min.js"></script>
<script>
    //获取输入框和按钮
    let inputs =document.querySelectorAll('input')
    var registerBtn = document.querySelector('button')
    registerBtn.onclick = function(){
        if(
            inputs[0].value &&
            inputs[1].value &&
            inputs[2].value &&
            inputs[3].value &&
            inputs[4].value 
        ){
            if(/^1[3-9]\d{9}$/.test(inputs[0].value)&&inputs[2].value ==inputs[3].value){
                axios.post('/user/register',{
                    phone:inputs[0].value,
                    name:inputs[1].value,
                    pass:inputs[2].value,
                    email:inputs[4].value
                }).then((res)=>{
                    // console.log(res.data);
                    alert('恭喜您，注册成功')

                })
            }else if(/^1[3-9]\d{9}$/.test(inputs[0].value) == false){
                alert('手机号格式不正确！')
            }else{
                alert('两次密码不一致！')
            }
        }else{
            alert('注册信息不完整！')
        }
    }
</script>